package com.honda.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.honda.model.User;
import com.honda.util.ResultUtils;

/***
 * 
 * @ClassName:  HttpController   
 * @Description: (http请求 支持 get、post,传输数据json)
 * @author: shikong
 * @date:   2018年7月4日 下午2:29:32      
 * @Copyright: 2018
 */
@SuppressWarnings("restriction")
@Controller
@RequestMapping("http")
public class HttpController extends ResultUtils {

	
	/**
	 * 
	 * @Title: saveUser   
	 * @Description: TODO(http post请求)   
	 * @param: @param param
	 * @param: @param req
	 * @param: @param resp      
	 * @return: void      
	 * @throws
	 */
	@RequestMapping(value="/save",method = RequestMethod.POST)
	public void saveUser(@RequestBody String param, HttpServletRequest req,
			HttpServletResponse resp) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		
		//end
		// Json转List
		/*List<User> users = JsonUtils.jsonToList(param, User.class);
		for (User u : users) {
			System.out.println("ID" + u.getId() + " UserName:"
					+ u.getUsername() + " usrPassword:" + u.getPassword());
		}*/
		// 业务处理
		User user = new User();
		user.setId("1111");
		user.setUsername("zhang");
		user.setPassword("san");
		jsonResult1(user, resp);//响应数据
	}
	
	
	/***
	 * 
	 * @Title: getUser   
	 * @Description: get 请求  
	 * @param: @param req
	 * @param: @param resp
	 * @param: @param userName      
	 * @return: void      
	 * @throws
	 */
	@RequestMapping(value="/getByUserId",method = RequestMethod.GET)
	public void getUser(HttpServletRequest req,
			HttpServletResponse resp,String userName) {

		// ESB 建议业务方将 esb httphead 入库，以便出现数据丢失问题方便双方查找 begin
		String requestID = req.getHeader("RequestID");
		String sourceSystem = req.getHeader("SourceSystem");
		String targetSystem = req.getHeader("TargetSystem");
		String serviceName = req.getHeader("ServiceName");

		System.out.println("requestld:" + requestID);
		System.out.println("sourceSystem:" + sourceSystem);
		System.out.println("targetSystem:" + targetSystem);
		System.out.println("serviceName:" + serviceName);
		//end
		System.out.println(userName);
		//业务处理
		User user = new User();
			user.setId("2222");
			user.setUsername("zhang");
			user.setPassword("san");
		// int i=100/0;
		jsonResult1(user, resp);//响应数据
	}
}
